<!DOCTYPE html>
<html lang="en">
<!--
	作者：梁颖
	时间：2019-05-29
	描述：资产负债表的添查修改
-->
	<head>
		<meta charset="UTF-8">
		<title>资产负债</title>
		<link rel="stylesheet" href="../../../js/bower_components/bootstrap/dist/css/bootstrap.min.css">
		<link rel="stylesheet" href="../../../js/bower_components/bootstrap-select/dist/css/bootstrap-select.min.css">
		<link rel="stylesheet" href="../../../js/bower_components/bootstrap-switch/dist/css/bootstrap3/bootstrap-switch.min.css">
		<link rel="stylesheet" href="../../../js/bower_components/bootstrap-table/dist/bootstrap-table.min.css">
		<link rel="stylesheet" href="../../../js/bower_components/bootstrap-treeview/dist/bootstrap-treeview.min.css">

		<script src="../../../js/bower_components/jquery/dist/jquery.min.js"></script>
		<script src="../../../js/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		<script src="../../../js/bower_components/bootbox.min.js"></script>
		<script src="../../../js/bower_components/bootstrap-select/js/bootstrap-select.js"></script>
		<script src="../../../js/bower_components/bootstrap-switch/dist/js/bootstrap-switch.min.js"></script>
		<script src="../../../js/bower_components/bootstrap-table/dist/bootstrap-table.min.js"></script>
		<script src="../../../js/bower_components/bootstrap-table/dist/locale/bootstrap-table-zh-CN.js"></script>

		<script src="../../../js/bower_components/bootstrap-treeview/dist/bootstrap-treeview.min.js"></script>
		<script src="../../../js/bower_components/jquery-form-validator/form-validator/jquery.form-validator.min.js"></script>
		<script src="../../../js/bower_components/moment/min/moment-with-locales.min.js"></script>
		<script>
			var temp_bid = 0;
			$(function() {
				$.ajax({
					type: "get",
					url: "http://127.0.0.1:8080/getAllB",
					dataType: "json",
					contentType: "application/json;charset=utf-8",
					success: function(data) {
						console.log(data);
						console.log(data.data.list)
						CreateBalanceTable(data.data.list)
					}
				});
//				CreateUserTable("");
				//新增数据
				$("#butAdd").click(function() {
					alert("ssss")
					$("#divData").modal();
				});
				//保存数据
				$("#btnSave").click(function() {
					var bid = $("#txtBalanceBid").val();
					var mf = $("#txtBalanceMf").val();
					var ar = $("#txtBalanceAr").val();
					var im = $("#txtBalanceIn").val();
					var ad = $("#txtBalanceAd").val();
					var ts = $("#txtBalanceTs").val();
					var at = $("#txtBalanceAt").val();
					var createt = $("#txtLoanCreatet").val();
					var updatet = $("#txtLoanUpdatet").val();
					var createp = $("#txtLoanCreatep").val();
					var updatep = $("#txtLoanUpdatep").val();
					var cid =$("#txtBalanceCid1").val();
					var str = '{"accountsr": "'+ar+'","accumulatedd": "'+ad+'","assetst": "'+at+'","bid": '+bid+',"cid": '+cid+',"createp": "'+createp+'","createt": "'+createt+'",';
  						str+='"immobilisation": "'+im+'","monetaryf": '+mf+',"totalfias": "'+ts+'","updatep": "'+updatep+'","updatet": "'+updatet+'"}'
					console.log(str);
					$.ajax({
						type: "put",
						url: "http://127.0.0.1:8080/addB",
						data: str,
						dataType: "json",
						contentType: "application/json;charset=utf-8",
						success: function(data) {
							console.log(data);
							if(data == 1) {
								$.ajax({
									type: "get",
									url: "http://127.0.0.1:8080/getAllB",
									dataType: "json",
									contentType: "application/json;charset=utf-8",
									success: function(data) {
										CreateBalanceTable(data.data.list);
										emptyData();
									}
								});
							}

						}
					});
				})
////				//删除数据
				$("#butDel").click(function() {
					var bid = temp_bid;
					alert("确认删除角色的主键是：" + bid)
					$.ajax({
						type: "get",
						url: "http://127.0.0.1:8080/delB",
						data: "bid=" + bid,
						dataType: "json",
						contentType: "application/json;charset=utf-8",
						success: function(data) {
							alert(data);
							if(data == 1) {
								$.ajax({
									type: "get",
									url: "http://127.0.0.1:8080/getAllB",
									dataType: "json",
									contentType: "application/json;charset=utf-8",
									success: function(data) {
										CreateBalanceTable(data.data.list)
									}
								});
							} else {
								alert("删除失败")
							}
						}
					});
				});
//				//修改数据之前获取数据的方法
//				$("#butEdit").click(function() {
//					var uid = temp_uid;
//					if(uid > 0) {
//						$.ajax({
//							type: "get",
//							url: "http://127.0.0.1:8080/getAll",
//							data: "uid=" + uid,
//							dataType: "json",
//							contentType: "application/json;charset=utf-8",
//							success: function(data) {
//								alert(data);
//								if(data != null) {
//									$("#divData").modal();
//									$("#txtUseruid").val(data.uid);
//									$("#txtUseruid").attr("readonly", "true");
//									$("#txtUserName1").val(data.uname);
//									console.log()
//									$("#seluisbegin1").selectpicker('val', data.uibegin);
//								} else {
//									alert("删除失败")
//								}
//							}
//						});
//					}
//				})
			});


			//对放款列表加载动态数据
			function CreateBalanceTable(data) {
				//			console.log("进入绑定事件"+data)
				$("#tabBalance").bootstrapTable("destroy");
				$("#tabBalance").bootstrapTable({
					loadMsg: "数据正在加载中....",
					uniqueId: "bid", //绑定列表主键（数据库主键）
					pageSize: 5,
					pagination: true,
					idFied: "bid",
					onClickRow: function(row) {
						alert(row.bid);
						temp_bid = row.bid;
					},
					data: data,
					columns: [{
						field: "bid",
						title: "主键"
					}, {
						field: "monetaryf",
						title: "货币资金"
					}, {
						field: "accountsr",
						title: "应收帐款"
					}, {
						field: "immobilisation",
						title: "固定资产原值"
					}, {
						field: "accumulatedd",
						title: "累计折旧"
					}, {
						field: "totalfias",
						title: "固定资产合计"
					},{
						field: "assetst",
						title: "资产合计"
					},{
						field: "createt",
						title: "创建时间"
					},{
						field: "updatet",
						title: "更新时间"
					}, {
						field: "createp",
						title: "创建人"
					}, {
						field: "updatep",
						title: "更新人"
					}, {
						field: "cid",
						title: "公司"
					}]
				});
			}
				//给下拉框绑定json数据


			//清空表单数据
			function emptyData() {
					$("#txtBalanceBid").val("");
					$("#txtBalanceMf").val("");
					$("#txtBalanceAr").val("");
					$("#txtBalanceIn").val("");
					$("#txtBalanceAd").val("");
					$("#txtBalanceTs").val("");
					$("#txtBalanceAt").val("");
					$("#txtLoanCreatet").val("");
					$("#txtLoanUpdatet").val("");
					$("#txtLoanCreatep").val("");
					$("#txtLoanUpdatep").val("");
					$("#txtBalanceCid1").val("");
			}
		</script>

	</head>

	<body>
		<div class="container-fluid">
			<!--查询区域-->
			<div class="row col-md-10">
				<div class="form-inline">
					<div class="form-group">
						<label class="control-label" for="txtBalanceCid">借款公司</label>
						<input class="form-control" id="txtBalanceCid" />
					</div>
					<div class="form-group">
						<button type="button" class="btn btn-primary">查询</button>
					</div>
				</div>
			</div>
			<br /><br /><br />
			<!--功能区域-->
			<div class="row col-md-10">
				<div>
					<button type="button" id="butAdd" class="btn btn-success">新增</button>
					<button type="button" id="butEdit" class="btn btn-info">修改</button>
					<button type="button" id="butDel" class="btn btn-danger">删除</button>
				</div>
			</div>
			<br /><br /><br />
			<!--列表区域-->
			<div class="row col-md-10">
				<table id="tabBalance"></table>
			</div>
			<!--表单区域-->
			<div class="modal fade" id="divData" tabindex="1">
				<div class="modal-dialog" style="width: 500px;">
					<div class="modal-content">
						<div class="modal-header">
							<h4 class="modal-title">新增负债信息</h4>
						</div>
						<div class="modal-body form-inline">
							<div class="form-group">
								<label class="control-label">主键</label>
								<input type="number" maxlength="20" class="from-control" id="txtBalanceBid" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">货币资金</label>
								<input type="text" maxlength="20" class="from-control" id="txtBalanceMf" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">应收帐款</label>
								<input type="text" maxlength="20" class="from-control" id="txtBalanceAr" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">固定资产原值</label>
								<input type="text" maxlength="20" class="from-control" id="txtBalanceIn" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">累计折旧</label>
								<input type="text" maxlength="20" class="from-control" id="txtBalanceAd" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">固定资产合计</label>
								<input type="text" maxlength="20" class="from-control" id="txtBalanceTs" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">资金合计</label>
								<input type="text" maxlength="20" class="from-control" id="txtBalanceAt" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">创建时间</label>
								<input type="date" maxlength="20" class="from-control" id="txtLoanCreatet" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">更新时间</label>
								<input type="date" maxlength="20" class="from-control" id="txtLoanUpdatet" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">创建人</label>
								<input type="text" maxlength="20" class="from-control" id="txtLoanCreatep" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">更新人</label>
								<input type="text" maxlength="20" class="from-control" id="txtLoanUpdatep" />
							</div>
							<br /><br />
							<div class="form-group">
								<label class="control-label">公司</label>
								<input type="text" maxlength="20" class="from-control" id="txtBalanceCid1" />
							</div>
							<br /><br />
							<div class="modal-footer">
								<button type="button" class="btn btn-success" id="btnSave" data-dismiss="modal">保存</button>
								<button type="button" class="btn btn-primary" id="btnClose" data-dismiss="modal">取消</button>
							</div>
							<br /><br />
						</div>
					</div>
				</div>
			</div>
		</div>

	</body>

</html>